package com.ruoyi.web.controller.admin;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.vo.BdmMemberRuleGetInfoVo;
import com.ruoyi.system.domain.vo.BdmMemberRuleVo;
import com.ruoyi.system.domain.vo.BdmReferrerVo;
import com.ruoyi.system.domain.vo.BdmTeamAdminVo;
import com.ruoyi.system.service.IBdmMemberRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 用户会员Controller
 *
 * @author ruoyi
 * @date 2024-12-09
 */
@RestController
@RequestMapping("/admin/rule")
@Validated
public class BdmMemberRuleController extends BaseController {

    @Autowired
    private IBdmMemberRuleService bdmMemberRuleService;

    /**
     * 查询会员列表
     *
     * @param dto
     * @return
     */
    @GetMapping("/selectPage")
    public TableDataInfo selectPage(BdmMemberRuleDto dto) {
        startPage();
        List<BdmMemberRuleVo> list = bdmMemberRuleService.selectPage(dto);
        return getDataTable(list);
    }

    /**
     * 新增会员
     *
     * @param dto
     * @return
     */
    @PostMapping("/saveUserMember")
    public AjaxResult saveUserMember(@Validated @RequestBody BdmMemberSaveDto dto) {
        return success(bdmMemberRuleService.saveUserMember(dto));
    }

    /**
     * 查询会员详情
     * @return {@link BdmMemberRuleGetInfoVo}
     */
    @GetMapping("/getInfo")
    public AjaxResult getInfo(@Valid @NotNull(message = "用户编号必传") Long sysUserid) {
        BdmMemberRuleGetInfoVo bdmMemberRuleGetInfoVo = bdmMemberRuleService.getInfo(sysUserid);
        return success(bdmMemberRuleGetInfoVo);
    }

    /**
     * 查询推荐人
     * @return {@link BdmReferrerVo}
     */
    @GetMapping("/getReferrer")
    public TableDataInfo getReferrer(Long userId,String phonenumber) {
        startPage();
        List<BdmReferrerVo> list = bdmMemberRuleService.getReferrer(userId,phonenumber);
        return getDataTable(list);
    }


    /**
     * 修改推荐人
     */
    @PutMapping("/putReferrer")
    public AjaxResult putReferrer(@Valid @RequestBody PutReferrerDto putReferrerDto) {
        return toAjax(bdmMemberRuleService.putReferrer(putReferrerDto));
    }


    /**
     * 充余额
     */
     @PutMapping("/modifyBalance")
     public AjaxResult modifyBalance(@Valid @RequestBody ModifyBalanceDto modifyBalanceDto){
         return toAjax(bdmMemberRuleService.modifyBalance(modifyBalanceDto));
     }


    /**
     * 充积分
     */
     @PutMapping("/modifyIntegral")
     public AjaxResult modifyIntegral(@Valid @RequestBody ModifyIntegralDto modifyIntegralDto){
         return toAjax(bdmMemberRuleService.modifyIntegral(modifyIntegralDto));
     }


    /**
     * 重置支付密码
     */
    @PutMapping("/putPaymentCode")
    public AjaxResult putPaymentCode(@NotNull(message = "用户id必填") Long userId)
    {
        return toAjax(bdmMemberRuleService.putPaymentCode(userId));
    }

    /**
     * 修改会员等级
     */
    @PutMapping("/changeMembershipLevel")
    public AjaxResult changeMembershipLevel(@Valid @RequestBody BdmChangeMembershipLevelDto bdmChangeMembershipLevelDto)
    {
        return toAjax(bdmMemberRuleService.changeMembershipLevel(bdmChangeMembershipLevelDto));
    }

    /**
     * 团队管理列表 包含对应用户的助力用户信息
     * @return {@link BdmTeamAdminVo}
     */
    @GetMapping("/getTeamAdminList")
    public TableDataInfo getTeamAdminList(BdmMemberRuleDto dto) {
        startPage();
        return getDataTable(bdmMemberRuleService.getTeamAdminList(dto));
    }

    /**
     * 团队管理用户换位编辑
     */
    @PostMapping("/teamUserExchange")
    public AjaxResult teamUserExchange(@RequestBody List<BdmMemberRuleDto> dtos) {
        return success(bdmMemberRuleService.teamUserExchange(dtos));
    }

    /**
     * 会员列表 选择推荐人
     *
     * @param dto
     * @return
     */
    @GetMapping("/selectPageList")
    public TableDataInfo selectPageList(BdmMemberRuleDto dto) {
        startPage();
        List<BdmMemberRuleVo> list = bdmMemberRuleService.selectPageList(dto);
        return getDataTable(list);
    }

    @GetMapping("/sort")
    public void sort() {
       bdmMemberRuleService.sort();
    }
}
